Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for userspace MSR handling #241

Merged
merged 3 commits into from
Nov 23, 2023

Conversation

00xc
Copy link
Contributor

@00xc 00xc commented Nov 15, 2023

Summary of the PR

Add support for userspace MSR handling. This is done by enabling the KVM_CAP_X86_USER_SPACE_MSR capability, which enables two new exits, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR. This allows a VMM to intercept reads and writes to invalid MSRs instead of having KVM automatically inject a #GP into the guest.

This PR adds safe wrappers around KVM_CAP_X86_USER_SPACE_MSR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR, some helper types and 2 relevant tests.

Requirements

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

roypat
roypat previously approved these changes Nov 15, 2023
@00xc
Copy link
Contributor Author

00xc commented Nov 16, 2023

Reordered Cap::X86UserSpaceMsr to keep a consistent ordering.

roypat
roypat previously approved these changes Nov 16, 2023
@00xc
Copy link
Contributor Author

00xc commented Nov 17, 2023

Rebased on main, fixed conflicts and updated coverage.

roypat
roypat previously approved these changes Nov 17, 2023
Add the appropriate types to allow for a VMM to intercept RDMSR and
WRMSR instructions if access to an MSR is denied. By default, KVM
injects #GP on denied accesses.

To do this we need to add a new Cap variant which corresponds to
KVM_CAP_X86_USER_SPACE_MSR, and two new VcpuExit variants that
correspond to KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR respectively.
We also need helper types to pass the relevant information about the
exit to the VMM.

Signed-off-by: Carlos López <[email protected]>
Add two tests to verify respectively that reading and writing to an
invalid MSR trigger a VcpuExit.

Signed-off-by: Carlos López <[email protected]>
@00xc
Copy link
Contributor Author

00xc commented Nov 20, 2023

Rebased on main and fixed conflicts.

@00xc
Copy link
Contributor Author

00xc commented Nov 23, 2023

Gentle ping for reviewers

@JonathanWoollett-Light JonathanWoollett-Light merged commit a569412 into rust-vmm:main Nov 23, 2023
19 checks passed
@andreeaflorescu andreeaflorescu mentioned this pull request Dec 22, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants